package net.lab1024.sa.admin.module.flowable.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import net.lab1024.sa.admin.module.flowable.annotation.EnterpriseAndApplicationCodeProperty;
import net.lab1024.sa.admin.module.flowable.domain.AjaxResult;
import net.lab1024.sa.admin.module.flowable.domain.FlowableFieldDef;
import net.lab1024.sa.admin.module.flowable.domain.FlowableFieldRef;
import net.lab1024.sa.admin.module.flowable.domain.FlowableFieldSearch;
import net.lab1024.sa.admin.module.flowable.page.TableDataInfo;
import net.lab1024.sa.admin.module.flowable.service.IFlowableFieldDefService;
import net.lab1024.sa.admin.module.flowable.service.IFlowableFieldRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 流程字段引用关系Controller
 *
 * @author ruoyi
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/flowable/ref")
public class FlowableFieldRefController extends BaseController
{
    @Resource
    private IFlowableFieldRefService flowableFieldRefService;
    @Resource
    private IFlowableFieldDefService flowableFieldDefService;
    /**
     * 查询流程字段引用关系列表
     */
    @SaCheckPermission("flowable:ref:list")
    @GetMapping("/list")
    public TableDataInfo list(FlowableFieldRef flowableFieldRef)
    {
        startPage();
        List<FlowableFieldRef> list = flowableFieldRefService.selectFlowableFieldRefList(flowableFieldRef);
        return getDataTable(list);
    }

    /**
     * 导出流程字段引用关系列表
     */
/*
    @SaCheckPermission("flowable:ref:export")
    @Log(title = "流程字段引用关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowableFieldRef flowableFieldRef)
    {
        List<FlowableFieldRef> list = flowableFieldRefService.selectFlowableFieldRefList(flowableFieldRef);
        ExcelUtil<FlowableFieldRef> util = new ExcelUtil<FlowableFieldRef>(FlowableFieldRef.class);
        util.exportExcel(response, list, "流程字段引用关系数据");
    }
*/

    /**
     * 获取流程字段引用关系详细信息
     */
    @SaCheckPermission("flowable:ref:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(flowableFieldRefService.selectFlowableFieldRefById(id));
    }

    /**
     * 新增流程字段引用关系
     */
    @SaCheckPermission("flowable:ref:add")
    @PostMapping
    public AjaxResult add(@RequestBody FlowableFieldRef flowableFieldRef)
    {
        return toAjax(flowableFieldRefService.insertFlowableFieldRef(flowableFieldRef));
    }

    /**
     * 修改流程字段引用关系
     */
    @SaCheckPermission("flowable:ref:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody FlowableFieldRef flowableFieldRef)
    {
        return toAjax(flowableFieldRefService.updateFlowableFieldRef(flowableFieldRef));
    }

    /**
     * 删除流程字段引用关系
     */
    @SaCheckPermission("flowable:ref:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(flowableFieldRefService.deleteFlowableFieldRefByIds(ids));
    }
    /**
     * 查询流程字段引用关系列表(不翻页,关联字段定义表查询)
     */
    @SaCheckPermission("flowable:ref:listCombination")
    @GetMapping("/listCombination")
    public AjaxResult listCombination(FlowableFieldSearch flowableFieldSearch)
    {
        List<FlowableFieldDef> list = flowableFieldDefService.listCombination(flowableFieldSearch);
        return success(list);
    }
}
